package sg.edu.nus.iss.vmcs.maintenance;

import java.awt.*;

import sg.edu.nus.iss.vmcs.store.*;
import sg.edu.nus.iss.vmcs.util.VMCSException;

public class CoinDisplay extends Panel {

	public final static String TITLE = "Quantity of Coins Available";

	private StoreService storeService;
	private MaintenanceController mCtrl;
	private ButtonItemDisplay bi;
	private int len;
	private int curIdx;

	public CoinDisplay(MaintenanceController mctrl) {
		mCtrl = mctrl;
		storeService = mCtrl.getMainController().getStoreService();
		len = storeService.getStoreSize(Store.CASH);
		StoreItem[] items = storeService.getStoreItems(Store.CASH);

		bi = new ButtonItemDisplay(TITLE, items, len);

		bi.addListener(new CoinDisplayListener(mCtrl));

		bi.clear();

		this.add(bi);

	}

	public void setActive(boolean st) {
		bi.setActive(st);
	}

	/**
	 * Display the quantity of selected coin, clear other display.
	 */
	public void displayQty(int idx, int qty) throws VMCSException {
		curIdx = idx;
		bi.clear();
		bi.displayQty(idx, qty);
	}

	/**
	 * get the current displayed coin index. This is used for updating when
	 * store MachinerySimulatorPanel is changed.
	 */
	public int getCurIdx() {
		return curIdx;
	}
}